﻿Imports SFDL.Core
Imports System.Windows.Forms
Imports SFDL.LoaderExtensions

Imports System.Threading

Public Class frm_speedreport

    Dim _settings As New SpeedreportSettings

    Public Property SpeedReportText As String

    Private Sub cmd_OK_Click(sender As Object, e As EventArgs) Handles cmd_OK.Click
        Me.Close()
    End Sub

    Private Sub LinkExplorer_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkExplorer.LinkClicked

        Dim _tools As New Tools

        Try
            _tools.OpenExplorer(GetSettings.DownloadDirectory)
        Catch ex As Exception
            MessageBox.Show("Verzeichniss konnte nicht geöffnet werden!", "Sorry...", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub frm_speedreport_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown

        Try

            rtb_speedreport.Clear()
            rtb_speedreport.Text = SpeedReportText

        Catch ex As Exception
            MessageBox.Show("Speedreport konnte nicht angezeigt werden!", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub KopierenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles KopierenToolStripMenuItem.Click

        Dim _copy_text As String = String.Empty

        _copy_text = rtb_speedreport.SelectedText

        If Not String.IsNullOrWhiteSpace(_copy_text) Then

            Dim _t As Thread

            _t = New Thread(CType(Sub() SetClipboardText(_copy_text), ThreadStart))
            _t.SetApartmentState(ApartmentState.STA)
            _t.Start()

        End If

    End Sub

    Private Sub cmd_clipboard_Click(sender As Object, e As EventArgs) Handles cmd_clipboard.Click

        Dim _copy_text As String = String.Empty

        _copy_text = rtb_speedreport.Text

        If Not String.IsNullOrWhiteSpace(_copy_text) Then

            Dim _t As Thread

            _t = New Thread(CType(Sub() SetClipboardText(_copy_text), ThreadStart))
            _t.SetApartmentState(ApartmentState.STA)
            _t.Start()

        End If

    End Sub

    Private Sub SetClipboardText(ByVal _text As String)
        My.Computer.Clipboard.SetText(_text)
    End Sub

End Class